import {createBrowserRouter} from "react-router-dom"
import Layout from "@/Layout.jsx";
import Login from "@/pages/login/index.jsx";
import Register from '@/pages/regist/index.jsx';
import Home from '@/pages/home/index.jsx';
import Profile from '@/pages/profile/index.jsx';
import Setting from '@/pages/setting/index.jsx';
import registAction from "@/pages/regist/registAction.js";
import loginAction from "@/pages/login/loginAction.jsx";
import logoutAction from "@/pages/setting/logoutAction.js";
import updataAction from "@/pages/setting/updataAction.js";
import Error from "@/components/Error.jsx";
import ArticleNew from "@/pages/article/articleNew/articleNew.jsx";
import loader from '@/pages/profile/loader.js'
import followAction from "@/pages/profile/followAction.js"
import articleNewAction from "@/pages/article/articleNew/articleNewAction.js"
import ArticleDetail from "@/pages/article/index.jsx"
import articleDetailLoadsh from "@/pages/article/articleDetailLoadsh.js"
import ArticleEdit from "@/pages/article/articleEdit/index.jsx"
import articleEditLoadsh from "@/pages/article/articleEdit/articleEditLoadsh.js"
import articleEditAction from "@/pages/article/articleEdit/articleEditAction.js"
import acticleFavoritedAction from "@/pages/article/acticleFavorited/acticleFavoritedAction.js"
import acticleDeleteAction from "@/pages/article/acticleDelete/acticleDeleteAction.js"
import homeLoader from "@/pages/home/homeLoader.js"
const router = createBrowserRouter([
    {
        path: "/",
        element: <Layout/>,
        errorElement: <Error/>,
        children: [
            {
                index: true,
                loader:homeLoader,
                element: <Home/>
            }, {
                path: "setting",
                action: updataAction,
                element: <Setting/>
            }, {
                path: "setting/logout",
                action: logoutAction,
            }, {
                path: "article/new",
                element: <ArticleNew/>,
                action: articleNewAction,
            }, {
                path: "profile/:username",
                loader: loader,
                action: followAction,
                element: <Profile/>
            }, {
                path: "article/:slug",
                element: <ArticleDetail/>,
                loader: articleDetailLoadsh,
                action: acticleFavoritedAction,
            }, {
                path: "article/:slug/edit",
                element: <ArticleEdit/>,
                loader: articleEditLoadsh,
                action: articleEditAction,
            }, {
                path: "article/:slug/delete",
                action: acticleDeleteAction
            },
        ]
    },
    {
        path: "/login",
        element: <Login/>,
        action: loginAction,
        errorElement: <Error/>,
    }, {
        path: "/regist",
        action: registAction,
        element: <Register/>,
        errorElement: <Error/>,
    }
])

export default router;